package com.team.cloudsharing.dao.user;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.team.cloudsharing.dao.folder.FolderDO;
import com.team.cloudsharing.dao.remember.RememberDO;
import com.team.cloudsharing.dao.sharefolder.ShareFolderDO;

@Entity
@Table(name = "user")
public class UserDO implements Serializable{

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "user_id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long userId;

	@Column(name = "user_email", nullable = false)
	private String userEmail;

	@Column(name = "user_name", nullable = false)
	private String userName;
	
	@Column(name = "password", nullable = false)
	private String password;
	
	@Column(name = "user_token", nullable = false)
	private String userToken;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "reg_date", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
	private Date regDate = new Date();
	
	@Column(name = "activation_code", nullable = true)
	private String activationCode;

	@Column(name = "is_activated", nullable = false)
	private boolean isActivated = false;
	
	@Column(name = "available_capacity", nullable = false)
	private Long availableCapacity = 104857600L;
	
	@Column(name = "used_capacity", nullable = false)
	private Long usedCapacity = 0L;
	
	@Column(name = "registration_id", nullable = true)
	private String registrationId;
	
	@OneToOne(mappedBy = "userDO", fetch = FetchType.EAGER)
	@Cascade({CascadeType.DELETE, CascadeType.SAVE_UPDATE})
	private RememberDO rememberDO;

	@OneToMany(mappedBy = "userDO", fetch = FetchType.EAGER)
	@Cascade({CascadeType.DELETE, CascadeType.SAVE_UPDATE})
	private Set<FolderDO> folderDO;
	
	@OneToMany(mappedBy = "userDO", fetch = FetchType.EAGER)
	@Cascade({CascadeType.DELETE, CascadeType.SAVE_UPDATE})
	private Set<ShareFolderDO> shareFolderDO;
	
	public UserDO(){
	}

	public UserDO(String userEmail, String userName, String password, Date regDate, String userToken, 
			String activationCode, boolean isActivated, String registrationId) {
		super();
		this.userEmail = userEmail;
		this.userName = userName;
		this.password = password;
		this.regDate = regDate;
		this.userToken = userToken;
		this.activationCode = activationCode;
		this.isActivated = isActivated;
		this.registrationId = registrationId;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getUserEmail() {
		return userEmail;
	}

	public void setUserEmail(String userEmail) {
		this.userEmail = userEmail;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUserToken() {
		return userToken;
	}

	public void setUserToken(String userToken) {
		this.userToken = userToken;
	}

	public Date getRegDate() {
		return regDate;
	}

	public void setRegDate(Date regDate) {
		this.regDate = regDate;
	}

	public String getActivationCode() {
		return activationCode;
	}

	public void setActivationCode(String activationCode) {
		this.activationCode = activationCode;
	}

	public boolean isActivated() {
		return isActivated;
	}

	public void setActivated(boolean isActivated) {
		this.isActivated = isActivated;
	}
	
	public Long getAvailableCapacity() {
		return availableCapacity;
	}

	public void setAvailableCapacity(Long availableCapacity) {
		this.availableCapacity = availableCapacity;
	}

	public Long getUsedCapacity() {
		return usedCapacity;
	}

	public void setUsedCapacity(Long usedCapacity) {
		this.usedCapacity = usedCapacity;
	}

	public Set<FolderDO> getFolderDO() {
		return folderDO;
	}

	public void setFolderDO(Set<FolderDO> folderDO) {
		this.folderDO = folderDO;
	}

	public RememberDO getRememberDO() {
		return rememberDO;
	}

	public void setRememberDO(RememberDO rememberDO) {
		this.rememberDO = rememberDO;
	}


	public String getRegistrationId() {
		return registrationId;
	}

	public void setRegistrationId(String registrationId) {
		this.registrationId = registrationId;
	}

	public Set<ShareFolderDO> getShareFolderDO() {
		return shareFolderDO;
	}

	public void setShareFolderDO(Set<ShareFolderDO> shareFolderDO) {
		this.shareFolderDO = shareFolderDO;
	}

}
